package com.jh.browser;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.WindowManager;

import com.jh.browser.R;
import com.jh.browser.common.Constant;

import java.lang.ref.WeakReference;

public class MainActivity extends AppCompatActivity {

    private MyHandler myHandler ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //全屏显示
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);
        /**
         * 启动跳转
         */
        myHandler = new MyHandler(this);
        myHandler.sendEmptyMessageDelayed(Constant.SUCCESS, 1200);
    }

    private static class MyHandler extends Handler {

        private WeakReference<Activity> reference;

        private MyHandler(Activity activity) {
            reference = new WeakReference<Activity>(activity);
        }

        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                //跳到主页
                case Constant.SUCCESS:
                    Activity activity = reference.get();
                    if (activity != null) {
                        activity.startActivity(new Intent(activity, BrowserActivity.class));
                        activity.finish();
                    }
            }
        }
    }
}
